import mysql.connector


# 创建一个连接数据库的工具类

def con():
    # 异常处理机制
    try:
        con = mysql.connector.connect(
            host='127.0.0.1',
            port='3306',
            user='root',
            password='123456',
            database='examtest'
        )
    except mysql.connector.Error as e:
        print('数据库连接失败')
    else:
        print('数据库连接成功······')
        return con


class JDBCUtils:
    def get_sql_con(db):
        # 异常处理机制
        try:
            con = mysql.connector.connect(
                host='127.0.0.1',
                port='3306',
                user='root',
                password='123456',
                database=db
            )
        except mysql.connector.Error as e:
            print('数据库连接失败')
        else:
            print('数据库连接成功······')
            return con
